package com.company.chu;

public class InsertSort {

    public static void main(String[] args) {
        int[] nums = {1,4,6,2,5,3,7,9};
        insert(nums);
        for (int n:nums) {
            System.out.println(n);
        }
    }




    public static void insert(int[] nums){
        int len = nums.length;
        for (int i =1;i<len;i++){
            int value = nums[i];
            int j  = i -1;
            for (;j>=0;j--){
                if(nums[j] > value){
                    nums[j+1] = nums[j];
                }else {
                    break;
                }
            }
            nums[j+1] = value;
        }
    }
}